package com.xbongbong.executor.query;

import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.interfaces.BusinessListService;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.constant.ParameterConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * @author sunshaoxiang
 * @ClassName CommonExecutor
 * @Description 通用 executor
 * @Date 2022/6/30 15:44
 * @Version 1.0
 **/
@Component
@Slf4j
public class CommonListQry {
    @Resource
    private Map<Integer, BusinessListService> businessListMap;


    public PaasFormDataEsListVO execute(FormDataListDTO formDataListDTO) throws XbbException {
        BusinessListService businessListService = businessListMap.get(formDataListDTO.getBusinessType());
        if (Objects.isNull(businessListService)) {
            log.error("businessType="+ formDataListDTO.getBusinessType());
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100404, I18nStringConstant.NOT_EXIST, ParameterConstant.BUSINESS_TYPE);
        }
        return businessListService.list(formDataListDTO);
    }


}
